package com.group6.exam.teacher.service;

import java.util.List;
import java.util.Map;

import com.group6.exam.common.entity.ExamEntity;
import com.group6.exam.common.entity.PageModel;
import com.group6.exam.teacher.dao.ExamDaoImpl;
import com.group6.exam.teacher.dao.IExamDao;

public class ExamServiceImpl implements IExamService {

	private IExamDao examDao = new ExamDaoImpl();

	/**
	 * 查询科目
	 */
	public List<Map<String, Object>> getSubject() {
		return examDao.getSubject();
	}

	/**
	 * 查询试卷
	 */
	public List<Map<String, Object>> getPaper() {
		return examDao.getPaper();
	}

	/**
	 * 查询发布试卷用户
	 */
	public List<Map<String, Object>> getUserInfo() {
		return examDao.getUserInfo();
	}

	/**
	 * 分页方法
	 */
	public PageModel getStudentPageByPageModel(PageModel pageModel, String gradeName) {
		int totalRecords = examDao.getTotalRecords(gradeName);
		int pageSize = pageModel.getPageSize();

		PageModel page = new PageModel(totalRecords, pageSize);

		page.setCurrentPage(pageModel.getCurrentPage());
		page.setList(examDao.getExamPage(pageModel, gradeName));
		return page;
	}

	/**
	 * 删除考试信息
	 */
	public int delete(String examId) {
		return examDao.delete(examId);
	}

	/**
	 * 修改前查询考试信息
	 */
	public Map<String, Object> preUpdate(String examId) {
		return examDao.preUpdate(examId);
	}

	/**
	 * 添加考试信息
	 */
	public int add(ExamEntity exam) {
		return examDao.add(exam);
	}

	/**
	 * 修改考试信息
	 */
	public int update(ExamEntity exam) {
		return examDao.update(exam);
	}

	/**
	 * 未参考页面分页方法
	 */
	public PageModel notExam(PageModel pageModel, String gradeName) {
		int totalRecords = examDao.notExamTotalRecords(gradeName);
		int pageSize = pageModel.getPageSize();
		
		PageModel page = new PageModel(totalRecords, pageSize);
		page.setCurrentPage(pageModel.getCurrentPage());
		page.setList(examDao.notExamList(pageModel, gradeName));
		
		return page;
	}

	/**
	 * 考试记录明细分页方法
	 */
	public PageModel examInfo(PageModel pageModel, String gradeName) {
		
		int totalRecords = examDao.getTotalRecords(gradeName);
		int pageSize = pageModel.getPageSize();
		
		PageModel page = new PageModel(totalRecords, pageSize);
		page.setCurrentPage(pageModel.getCurrentPage());
		page.setList(examDao.examInfo(pageModel, gradeName));
		
		return page;
	}

}
